<template>
  <div class="login">
    <p>×</p>
    <h3>密码登录</h3>
    <div class="data">
      <div class="inp">
        <input type="text" placeholder="手机/用户名" v-model="form.admin" />
      </div>
      <div class="inp">
        <input type="password" placeholder="密码" v-model="form.password" />
      </div>
      <p class="go" @click="go">去注册</p>
      <button @click="login" :class="{ static: this.form.admin }">登录</button>
      <div class="tishi">
        <p>手机号登录</p>
        <p>忘记密码</p>
      </div>
      <p class="bottom">
        <input type="radio" /> 已阅读并同意<span class="tiaoyue"
          >《用户服务协议》、《隐私政策》</span
        >
      </p>
    </div>
  </div>
</template>
<script>
import { user_login } from "../../api/index.js";
export default {
  methods: {
    login() {
      console.log("账号为：" + this.form.admin);
      console.log("密码为：" + this.form.password);
      // this.form.admin = "";
      // this.form.password = "";
      user_login({ phone: this.form.admin, pass: this.form.password }).then(
        (res) => {
          console.log(res.data);
          alert(res.data.msg);
          if (res.data.code == 200) {
            window.localStorage.setItem('userid', res.data.userinfo.id)
            window.localStorage.setItem('token', res.data.token)
            this.$router.push('/home');
          }
        }
      );
    },
    go(){
      this.$router.push('/register');
    }
  },
  data() {
    return {
      form: [{ admin: "", password: "" }],
    };
  },
};
</script>

<style scoped>
.login {
  padding: 20px;
}

p {
  font-size: 25px;
}

h3 {
  margin-top: 30px;
}

.inp {
  margin: 30px 0;
}

.inp input {
  width: 100%;
  height: 30px;
  outline: none;
  border: 0;
  border-bottom: 1px solid gray;
}

button {
  width: 100%;
  height: 30px;
  border: 0;
  border-radius: 10px;
  background-color: rgb(202, 198, 198);
  color: gray;
  transition: all 0.3s;
  margin-top: 10px;
}
.data .static {
  color: white;
  background-color: blueviolet;
}

.data .tishi {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}
.data .go{
  color: blue;
  font-size: 13px;
}
.data .tishi p {
  color: blue;
  font-size: 13px;
}

.data .tiaoyue {
  color: blue;
}

.bottom {
  font-size: 12px;
  margin-top: 150px;
}

.bottom input {
  vertical-align: middle;
}
</style>
